package edu.szu.huhanpeng.doodlingFight.controller.showController.appStart 
{
	import com.bit101.components.Panel;
	import com.bit101.components.PushButton;
	import edu.szu.huhanpeng.doodlingFight.globalConst.GlobalConst;
	import edu.szu.huhanpeng.doodlingFight.globalConst.Setting;
	import edu.szu.huhanpeng.doodlingFight.model.data.GameData;
	import edu.szu.huhanpeng.doodlingFight.model.GameProxy;
	import edu.szu.huhanpeng.doodlingFight.view.StagePanelMed;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import org.puremvc.as3.interfaces.ICommand;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.interfaces.INotifier;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	/**
	 * ...
	 * @author Huhanpeng
	 */
	public class WelcomeSc extends SimpleCommand implements ICommand, INotifier 
	{
		private static const setting:Setting = GlobalConst.setting;
		
		override public function execute(note:INotification):void 
		{
			var stagePanel:Panel = facade.retrieveMediator( StagePanelMed.NAME ).getViewComponent() as Panel;
			var welcomePanel:Panel = new Panel( stagePanel, setting.WELCOME_PANEL_X, setting.WELCOME_PANEL_Y );
			welcomePanel.setSize( setting.WELCOME_PANEL_WIDTH, setting.WELCOME_PANEL_HEIGHT );
			
			var OPButton:PushButton = new PushButton( welcomePanel, setting.OP_BUTTON_X, setting.OP_BUTTON_Y, setting.OP_BUTTON_LABEL, onClick );
			var TPButton:PushButton = new PushButton( welcomePanel, setting.TP_BUTTON_X, setting.TP_BUTTON_Y, setting.TP_BUTTON_LABEL, onClick );
			var settingButton:PushButton = new PushButton( welcomePanel, setting.SETTING_BUTTON_X, setting.SETTING_BUTTON_Y, setting.SETTING_BUTTON_LABEL, onClick );
			setBtnSize(OPButton);
			setBtnSize(TPButton);
			setBtnSize(settingButton);
		}
		
		private function setBtnSize(button:PushButton):void 
		{
			button.setSize( setting.WELCOME_BUTTON_WIDTH, setting.WELCOME_BUTTON_HEIGHT );
		}
		
		private function onClick(e:Event):void 
		{
			var gameProxy:GameProxy = facade.retrieveProxy( GameProxy.NAME ) as GameProxy;
			
			switch ( (e.currentTarget as PushButton).label ) 
			{
				case setting.OP_BUTTON_LABEL:
					gameProxy.setGameMode( GameData.ONE_PLAYER );
					sendNotification( GlobalConst.noteName.GAME_START );
				break;
				
				case setting.TP_BUTTON_LABEL:
					gameProxy.setGameMode( GameData.TWO_PLAYER );
					sendNotification( GlobalConst.noteName.GAME_START );
				break;
				
				case setting.SETTING_BUTTON_LABEL:
					sendNotification( GlobalConst.noteName.OPEN_SETTING_PANEL );
				break;
				default:
			}
		}
		
	}

}